#define DEBUG
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=100000;

long long max(long long a, long long b) {
  return a>b ? a : b;
}

class Ele {
public:
  long long v, l;

  static bool cmpa(Ele a, Ele b) {
    return a.l<b.l;
  }

  static bool cmpb(Ele a, Ele b) {
    return a.l+a.v<b.l+b.v;
  }
};

class Tree {
public:
  int n, m, ind[maxn+1], to[2*maxn-1], link[2*maxn-1];
  long long sum[maxn+1], f[maxn+1], val[2*maxn+1], node[maxn+1], fav[maxn+1];

  void addSide(int u, int v, int w) {
    m++;
    to[m] = v;
    val[m] = w;
    link[m] = ind[u];
    ind[u] = m;
  }

  void build(int o, int fa) {
    sum[o] = node[o];
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	fav[to[i]] = val[i];
	build(to[i], o);
	sum[o] += sum[to[i]]-2*val[i];
      }
    }
  }

  long long solve(int o, int fa) {
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	f[to[i]] = solve(to[i], o);
      }
    }
    static Ele elea[maxn+1], eleb[maxn+1];
    int an=0, bn=0;
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	if (sum[to[i]]-2*val[i]>=0) {
	  elea[++an].l = val[i]+f[to[i]];
	  elea[an].v = sum[to[i]]-2*val[i];
	} else {
	  eleb[++bn].l = val[i]+f[to[i]];
	  eleb[bn].v = sum[to[i]]-2*val[i];
	}
      }
    }

    sort(elea+1, elea+an+1, Ele::cmpa);
    sort(eleb+1, eleb+bn+1, Ele::cmpb);

    long long ret=0, s=node[o];
    for (int i=1; i<=an; i++) {
      if (s<elea[i].l) {
	ret += elea[i].l-s;
	s = elea[i].l;
      }
      s += elea[i].v;
    }
    for (int i=1; i<=bn; i++) {
      s += eleb[i].v;
    }
    if (s<fav[o]) {
      ret += fav[o]-s;
      s = fav[o];
    }
    for (int i=1; i<=bn; i++) {
      if (s-eleb[i].v<eleb[i].l) {
	ret += eleb[i].l+eleb[i].v-s;
	s = eleb[i].l+eleb[i].v;
      }
      s -= eleb[i].v;
    }
    return ret;
  }
};

int main() {
  freopen("horse.in", "r", stdin);
  freopen("horse.out", "w", stdout);

  static Tree tree;
  int n;
  scanf("%d", &n);
  tree.n = n;
  for (int i=1; i<=n; i++) {
    scanf("%lld", tree.node+i);
  }
  for (int i=1; i<n; i++) {
    int u, v;
    long long w;
    scanf("%d %d %lld", &u, &v, &w);
    tree.addSide(u, v, w);
    tree.addSide(v, u, w);
  }

  tree.build(1, 0);
  printf("%lld", tree.solve(1, 0));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
